<?php
/**
 * 定义f:field相关控件
 * 
 * 定义了以下标签：
 * - <f:text/>
 * - <f:field/> 同<f:text/>
 * - <f:hidden/>
 * - <f:password/>
 * - <f:file/>
 * 
 * <f:file/>可以使用以下属性：
 * - 
 *
 * @since 1.1.0
 * @package if
 * @subpackage module.ui
 */
class UIFormField extends UIFormElement {
	protected $tpl = "form_field";
	private $isText = false;
	private $isHidden = false;
	private $isPassword = false;
	private $isFile = false;
	
	function requestValue() {
		if ($this->name() == "f:file") {
			if (IApplication::hasModule("upload")) {
				$upload = IUpload::instance()->fields($this->indexedName());
				return $upload->file($this->indexedName());
			}
			return; 
		}
		return parent::requestValue();
	}
	
	function _after_parse() {
		parent::_after_parse();
		switch ($this->name()) {
			case "f:text": $this->isText = true; break;
			case "f:field": $this->isText = true; break;
			case "f:hidden": $this->isHidden = true; break;
			case "f:password": $this->isPassword = true; break;
			case "f:file": 
				$this->isFile = true;  
				$this->reserveAttrs[] = "value";
				$form = $this->parent("f:form");
				if ($form) {
					$form->setAttr("enctype", "multipart/form-data");
				}
				break;
		}
		
		if (!$this->attr("type")) {
			$type = "text";
			if ($this->isHidden) {
				$type = "hidden";
			}
			else if ($this->isPassword) {
				$type = "password";
			}
			else if ($this->isFile) {
				$type = "file";
			}
			$this->setAttr("type", $type);
		}
		
		//readonly
		if ($this->attr("readonly")) {
			$this->setAttr("readonly", "readonly");
		}
		
		//disabled
		if ($this->attr("disabled")) {
			$this->setAttr("disabled", "disabled");
		}
	}
}

?>